/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.simba.utils.tree;

/**
 *
 * @author lejtovicz
 */
public class Sentiment {

    private static Tree t;

    public Tree getT() {
        return t;
    }

    public Sentiment() {
        t = new Tree();
    }

    public void setT(Tree t) {
        this.t = t;
        this.t.ws = new WordScore();
        this.t.ws.loadSentiments("c:\\Users\\lejtovicz\\Downloads\\twitter_sentiment_list_2.csv");
        //this.t.ws.loadSentiments("D:/Downloads/twitter_sentiment_list.csv");
    }

    public static Tree getDependencies(String dependencies) {
        Tree result = new Tree();
        String lines[] = dependencies.split("\n");
        String split[];
        String d;
        String edgeType;
        for (int i = 0; i < lines.length; i++) {
            if (lines[i].contains("(") && lines[i].contains(")")) {
                edgeType = lines[i].substring(0, lines[i].indexOf("("));
                d = lines[i].substring(lines[i].indexOf("(") + 1, lines[i].lastIndexOf(")"));
                split = d.split(", ");
                result.addEdge(split[0], split[1], edgeType);
            }
        }

        return result;
    }

    public Double getSentiment(String sentence, String entity, String role) {

        t = getDependencies(sentence);
        Tree tree = getDependencies(sentence);
        setT(tree);
        System.out.println(Sentiment.t.edges);
        Double sentimentScore = Sentiment.t.getSentiment(entity, role);
        return sentimentScore;
    }
}
